package com.cheetah.start;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.io.IOException;

/**
 * 启动类
 *
 * @author Feel
 * @date 2021/09/20
 */
@Slf4j
@EnableAsync
@SpringBootApplication(proxyBeanMethods = false)
@ServletComponentScan
@EnableTransactionManagement
public class FastApplication extends SpringBootServletInitializer {


    public static void main(String[] args) {
        ConfigurableApplicationContext run = SpringApplication.run(FastApplication.class, args);
        ConfigurableEnvironment environment = run.getEnvironment();
        String port = environment.getProperty("server.port");
        String path = environment.getProperty("server.servlet.context-path");
        String viewPath = "http://localhost:" + port + path + "/login";
        try {
            Runtime.getRuntime().exec("cmd /c start " + viewPath);
        } catch (IOException e) {
            log.error("页面打开失败", e);
        }
        System.out.println(" ┌-------------------------cheetah启动成功---------------------------┐");
        System.out.println("            页面地址: " + viewPath + "            ");
        System.out.println(" └-------------------------cheetah启动成功---------------------------┘");

    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(FastApplication.class);
    }
}
